<extend name="Public/base"/>

<block name="body">
    <style>
        .img-square{
            /*border: 1px solid red;*/
            margin-left: 30px;
            margin-top: 10px;
        }
        .closeLayer{
            /*display: none;*/
            z-index: 9999999999;
            position:absolute; /*绝对定位*/
            left:400px; /*位置自己看着调整，在图片上方*/
            top:100px;
            /*border: 1px solid red;*/
        }
    </style>
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>添加健康档案</h2>
    </div>
    <hr>
        <div class="form-item">
                    <label class="item-label">手机号</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="user_tel" id="user_tel" value="{$info.tel}">
                         <button class="btn ajax-post" id="check">获取</button>
                    </div>
        </div>
        <hr>
    <form action="{:U('Member/healthy_add')}" method="post" class="form-horizontal">
        <div class="form-item">
                    <label class="item-label">姓名</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="name" value="{$info.name}">
                        <input name="user_id" type="hidden" value="{$info.id}"/>
                    </div>
        </div>
        <div class="form-item">
                    <label class="item-label">身份证号</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="pernumber" value="{$info.pernumber}">
                    </div>
        </div>
        <div class="form-item">
                    <label class="item-label">联系电话</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="tel" value="{$info.tel}">
                    </div>
        </div>
        <div class="form-item">
                    <label class="item-label">银行卡号</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="bankcode" value="{$info.bankcode}">
                    </div>
        </div>
        <div class="form-item">
                    <label class="item-label">年龄</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="age" value="{$info.age}">
                    </div>
        </div>
        <div class="form-item">
                    <label class="item-label">从事行业</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="industry" value="{$info.industry}">
                    </div>
        </div>
        <label class="item-label">性别</label>
        <div class="form-item">
            <select name="user_sex">
                <option value="1" selected="">男</option>
                <option value="2">女</option>
            </select>
        </div>
        <label class="item-label">当前家庭住址:<span id="address" style="color:#0000ff">{$info.add_1}{$info.add_2}{$info.add_3}</span></label>
        <br/>
        <label class="item-label">家庭住址 <span style="color:red;" id="change_address">（如果要更改地址请选择）</span></label>
        {:hook('J_China_City')}
        <div class="form-item">
                    <label class="item-label">详细地址</label>
                    <div class="controls">
                         <input type="text" class="text input-large" name="add_4" value="{$info.add_4}">
                    </div>
        </div>
        <div class="form-item">
                <label class="item-label">备注(用户信息备注)</label>
                <div class="controls">
                <label class="textarea input-large">
                    <textarea name="user_content">{$info.content}</textarea>
                </label>
                </div>
        </div>
        <hr/>
        <div class="form-item">
            <label class="item-label">备注(健康档案)</label>
            <div class="controls">
                <label class="textarea input-large">
                    <textarea name="healthy_content"></textarea>
                </label>
            </div>
        </div>
        <input name="pic_path" type="hidden" id="pic_path"/>
    </form>
    <div class="controls">
        <input type="file" id="file_upload">
        <div id="div_pic" class="upload-pre-item">

        </div>
    </div>
    <br/>
    <div class="controls" id="old_pic">
        <label class="item-label">以往健康档案</label>
        <volist name="img" id="vo">
            <div>
                <img class="img-square" src="__ROOT__{$vo.path}" width="200" height="200">
                <span>{$vo.content}</span>
                <a href="{:U('Member/healthy_del?id='.$vo['id'])}" class="confirm ajax-get">删除</a>
            </div>
        </volist>
    </div>
    <br/>
    <div class="controls">
        <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>
</block>

<block name="script">
<script>
    function uploadPicture(file, data)
    {
        var data = $.parseJSON(data);
        var src = '__ROOT__/Uploads/'+data.savepath+data.savename;
        $('#pic_path').val('/Uploads/'+data.savepath+data.savename);
        $('#div_pic').html("<img src='"+src+"'  width='200' height='200'/>");

    }
    $(function () {
        $("#file_upload").uploadify({
            "height"          : 30,
            "swf"             : "__STATIC__/uploadify/uploadify.swf",
            "fileObjName"     : "download",
            "buttonText"      : "上传图片",
            "uploader"        : "{:U('File/member_upload')}",
            "width"           : 120,
            'removeTimeout'	  : 1,
            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
            "onUploadSuccess" : uploadPicture,
            'onFallback' : function() {
            alert('未检测到兼容版本的Flash.');
        }
    });
        var sex = '{$info.sex}';
        if (sex == '') {
            return;
        } else {
            $("[name='user_sex']").val(sex);
        }
    });
    $('#check').click(function() {
        $.post("{:U('Member/integral_getinfo')}",{'tel':$('#user_tel').val()},function (data) {
            if (data.reg == 2) {
                alert(data.info);
                $('input').attr("disabled",true);
                $("input[name='user_tel']").attr("disabled",false);
            } else {
                $('input').attr("disabled",false);
                for (var i in data['info']) {
                    $("input[name='" + i + "']").val(data['info'][i]);
                }
                $("[name='content']").val(data['info']['content']);
                $("[name='user_sex']").val(data['info']['sex']);
                $('#address').text(data['info']['add_1'] + data['info']['add_2'] + data['info']['add_3']);
                //var img = "<img src='"+src+"'  width='200' height='200'/>";
                var div = '';
                for (var i=0; i<data.img.length;i++) {
                    console.log(data.img[i]);
                    div +="<div>";
                    div += "<img class='img-square' src='__ROOT__"+data.img[i]['path']+"' width='200' height='200'>";
                    div += "<span>"+data.img[i]['content']+"</span>";
                    div += "<a href='/index.php?s=/Admin/Member/healthy_del/id/"+data.img[i]['id']+".html' class='confirm ajax-get'>删除</a>";
                    div += "</div>";
                }
                  $('#old_pic').html(div);
            }
        })
    });

</script>
</block>
